﻿


var isIe = (document.all) ? true : false;
//设置select的可见状态
function setSelectState(state) {
    var objl = document.getElementsByTagName('select');
    for (var i = 0; i < objl.length; i++) {
        objl[i].style.visibility = state;
    }
}
function mousePosition(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft, y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
//弹出方法
function showMessageBox(wTitle, content, pos, wWidth) {
    closeWindow();
    var bWidth = parseInt(document.documentElement.scrollWidth);
    var bHeight = parseInt(document.documentElement.scrollHeight);
    if (isIe) {
        setSelectState('hidden');
    }
    var back = document.createElement("div");
    back.id = "back";
    var styleStr = "top:0px;left:0px;position:absolute;background:#666;width:" + bWidth + "px;height:" + bHeight + "px;";
    styleStr += (isIe) ? "filter:alpha(opacity=0);" : "opacity:0;";
    back.style.cssText = styleStr;
    document.body.appendChild(back);
    showBackground(back, 50);
    var mesW = document.createElement("div");
    mesW.id = "mesWindow";
    mesW.className = "mesWindow";
    mesW.innerHTML = "<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>" + wTitle + "</td><td style='width:1px;'><input type='button' onclick='closeWindow();' title='关闭窗口' class='close' value='关闭' /></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>" + content + "</div><div class='mesWindowBottom'></div>";
    var v_top = (document.body.clientHeight - mesW.clientHeight) / 2;
    v_top += document.documentElement.scrollTop;
    styleStr = "top:" + (v_top - 180) + "px;left:" + (document.body.clientWidth / 2 - mesW.clientWidth / 2) + "px;position:absolute;width:600px;margin-left:-300px;left:50%;z-index:9999;";
    mesW.style.cssText = styleStr;
    document.body.appendChild(mesW);
}
//让背景渐渐变暗
function showBackground(obj, endInt) {
    if (isIe) {
        obj.filters.alpha.opacity += 5;
        if (obj.filters.alpha.opacity < endInt) {
            setTimeout(function () { showBackground(obj, endInt) }, 5);
        }
    } else {
        var al = parseFloat(obj.style.opacity); al += 0.05;
        obj.style.opacity = al;
        if (al < (endInt / 100))
        { setTimeout(function () { showBackground(obj, endInt) }, 5); }
    }
}
//关闭窗口
function closeWindow() {
    if (document.getElementById('back') != null) {
        document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    }
    if (document.getElementById('mesWindow') != null) {
        document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    }
    if (isIe) {
        setSelectState('');
    }
}
//更改房间状态
function testMessageBox(ev) {
    var objPos = mousePosition(ev);
    var  messContent = "<div style='padding:10px 0 20px 0;text-align:left;height: 100px'>" +
                     "<div style='float:left;width:30%;'>" +
                         "<hr style='width:0.1px; size:0.5px; color:#FFFFFF; '/>" +
                    "</div>" +
                    "<div style='float:left;width:12%'>" +
                        "<ul>" +
                            "<li>房间名称：</li> <br/>" +

                            "<li>房态：</li> <br/>" +

                            "<li>设置为：</li> <br/><br/>" +

                            "<li><input id='ajaxBtn' type='button' value='更改' onclick='btnClick()' /></li>" +
                        "</ul>" +
                    "</div>" +
                    "<div style='float:left;width:40%'>" +
                            "<li id='name'></li> <br/>" +
                            "<li id='state'></li> <br/>" +
                            "<li>" +
                                "<select>" +
                                    "<option  style='width: 60px' value='空闲'>空闲</option>" +
                                    "<option  style='width: 60px' value='入住'>入住</option>" +
                                    "<option  style='width: 60px' value='维修'>维修</option>" +
                                    "<option  style='width: 60px' value='打扫'>打扫</option>" +
                                    "<option  style='width: 60px' value='预定'>预定</option>" +
                                "</select>" +
                            "</li>" +
                    "</div>" +
                "</div>";
    showMessageBox('更改状态', messContent, objPos, 200);
    
}

//获得入住人数
function numberOfClient(event) {
    
    var objp = mousePosition(event);
    var  mess = "<div style='padding:20px 0 20px 0;text-align:center;height: 100px'>" +
                "<p id='rid'></p><br>" +
                "入住人数：<input type='text' id='clientNum' />" +
                "<br/><br/><br/>" +
                "<input id='inputBtn' type='button' value=' 确定 ' onclick='getNumber()' />" +
            "</div>"  ;  
              
    showMessageBox('请输入入住人数', mess, objp, 100);
}

function getNumber() {
    
    if (!isNaN($("#clientNum").val()) && $("#clientNum").val() != '' && $("#clientNum").val() != '0') {
        window.location.href = "/Client/FillUpAForm/?roomId=" +roomID+"&numberOfClient=" + $("#clientNum").val();
    } else {
        alert("这里不能为空，不能为零，并且只能输入数字，请重新输入！！");
    }
}


var id = "";
var roomID = "";
$(document).ready(function () {
    $("#show li").click(function () {

        if ($(this).val() == "1") {
            roomID = $(this).attr("id");
            var empty = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            $("#rid").html("房间编号：" + roomID + empty);
        }
        if ($(this).val() == "2") {
            $("#state").html("已用房");
        }
        if ($(this).val() == "3") {
            $("#state").html("维修房");
        }
        if ($(this).val() == "4") {
            $("#state").html("打扫");
        }
        if ($(this).val() == "5") {
            $("#state").html("预定");
        }
        $("#name").html($(this).attr("id"));
        id = $(this).attr("id");
    });
    
});


function btnClick() {
    if (confirm("确定要修改吗？")) {
        var room = {};
        room.id = id;
        if ($('select option:selected').val() == "空闲") {
            room.roomStateId = 1;
        }
        if ($('select option:selected').val() == "入住") {
            room.roomStateId = 2;
        }
        if ($('select option:selected').val() == "维修") {
            room.roomStateId = 3;
        }
        if ($('select option:selected').val() == "打扫") {
            room.roomStateId = 4;
        }
        if ($('select option:selected').val() == "预定") {
            room.roomStateId = 5;
        }
        $.post("/Room/ChangeRoomState", { "id": room.id, "roomStateId": room.roomStateId}, function () { });
        
        window.location.reload();
    }
}
